/**
 * Created with Intellij IDEA.
 * Description:
 * User: 86135
 * Date: 2023-07-13
 * Time: 9:49
 */
public class MySingleList {
    class ListNode{
          public int val;
          public  ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;//永远指向头结点

    public void createList(){
        ListNode node1 = new ListNode(12);
        ListNode node2 = new ListNode(23);
        ListNode node3 = new ListNode(34);
        ListNode node4 = new ListNode(45);
        ListNode node5 = new ListNode(56);
        node1.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;

        this.head = node1;

    }

    public void show(){
        ListNode cur = head;//定义一个引用,而非节点
        while(cur!=null){
            System.out.print(cur.val+" ");
            cur = cur.next;
        }
        System.out.println();
    }
    //得到单链表的长度 链表中节点的个数
    public int size(){
        ListNode cur = head;
        int count = 0;
        while(cur != null){
            count++;
            cur = cur.next;
        }
        return count;
    }
    //查找是否包含关键字key在单链表中
    public boolean contains(int key){
        ListNode cur = head;
        while(cur != null){
            if(cur.val == key) return true;
            cur = cur.next;
        }
        return false;
    }
    //头插入
    public void addFirst(int data){
        
    }
    //尾插入
    public void addLast(int data){

    }
    //任意位置插入,第一个数节点为0下标
    public void addIndex(int index,int data){

    }
    //删除第一次出现关键字key的节点
    public void remove(int key){

    }

    public void clear(){

    }

}
